/**
 * Created by zhanglihe on 15/11/7.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'collection',
    'template',
    'model',
    'dialog'
], function ($, common, ready, Collection, template, Model, dialog) {
    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            loading();
            this.fetch();
            this.event();
        },

        fetch: function () {
            this.data = {};
            var _this = this;

            this.collection = new Collection({
                url: _global.url.api + 'nine_point_nine',
                model: {
                    //url:_global.url.api + 'nine_point_nine',
                },
                render: function () {
                    var isVisible = this.result.data.isVisible ? this.result.data.isVisible : '';
                    var unVisible = this.result.data.unVisible ? this.result.data.unVisible : '';
                    $('#isVisible').val(isVisible);
                    $('#unVisible').val(unVisible);
                    return this;
                },
                callback: function () {
                    loaded();
                },
            });
            this.collection.fetch();
        },

        event: function () {
            this.data = {};
            var _this = this;

            $('#isVisible').on('change', function (e) {
                e.preventDefault();
                var isVisible = $("#isVisible").val();
                if (!isVisible) {
                    return false;
                }
                if (new Model({
                        url: _global.url.api + 'nine_point_nine',
                        data: {isVisible: isVisible}
                    }).put()) {
                    _this.collection.fetch();
                }
                ;
            });

            $('#unVisible').on('change', function (e) {
                e.preventDefault();
                var unVisible = $("#unVisible").val();
                if (new Model({
                        url: _global.url.api + 'nine_point_nine',
                        data: {unVisible: unVisible}
                    }).del()) {
                    _this.collection.fetch();
                }
                ;
            });

        },


    };

    new index();

});